#include "bits/stdc++.h"

using namespace std;

const int N = 4;

int dp[1 << N];

int bit_count(int i)
{
    int res = 0;
    while (i)
    {
        if (i & 1)
            res++;
        i >>= 1;
    }
    return res;
}

int minimumXORSum(vector<int> &nums1, vector<int> &nums2)
{
    int n = nums1.size();

    memset(dp, 0x3f, sizeof(dp));

    dp[0] = 0;
    for (int i = 1; i < (1 << n); i++)
    {
        int ci = bit_count(i);
        for (int j = 0; j < n; j++)
        {
            // i的第j位是1, 可以转移
            if (i & (1 << j))
            {
                dp[i] = min(dp[i], dp[i - (1 << j)] + (nums2[j] ^ nums1[ci - 1]));
            }
        }
    }

    return dp[(1 << n) - 1];
}

int main()
{
    int n;
    cin >> n;
    vector<int> a, b;

    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        a.push_back(x);
    }
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        b.push_back(x);
    }

    cout << minimumXORSum(a, b) << endl;
    return 0;
}
/*
3
1 0 3 
5 3 4

2
1 2
2 3
*/